package leetcode;

import java.util.HashMap;
import java.util.HashSet;

/**
 * Created with IntelliJ IDEA.
 * Description:142. 环形链表 II
 * User: 东莞呵呵
 * Date:2022-07-10
 * Time:10:50
 */
public class TestDemo3 {
    public ListNode detectCycle(ListNode head) {
        HashSet<ListNode> set=new HashSet<>();
        ListNode cur=head;
        while(cur!=null){
            if(set.contains(cur)){
                return cur;
            }else{
                set.add(cur);
            }
            cur=cur.next;
        }
        return null;
    }
}
